<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>添加客户</title>
		<link rel="stylesheet" type="text/css" href="${BASE_PATH}/static/lib/layui/css/layui.css" />
	</head>

	<body>
		<form class="layui-form" action="" style="margin: 10px 10px 0 10px;">
			<div class="layui-form-item">
				<label class="layui-form-label">姓名</label>
				<div class="layui-input-inline">
					<input type="text" name="name" lay-verify="yhUserName" placeholder="" autocomplete="off" class="layui-input">
				</div>
				<label class="layui-form-label">用户名</label>
				<div class="layui-input-inline">
					<input id="idCard" type="text" name="phone" placeholder="" autocomplete="off" class="layui-input idCard" lay-verify="required">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
				<label class="layui-form-label">权限</label>
					<div class="layui-input-inline">
						<select  name="jurisdiction" lay-verify="required" lay-search="">
							<option value="">选择权限</option>
							<option value="1">超级管理员</option>
							<option value="2">财务人员</option>
							<option value="3">业务员</option>
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">状态</label>
					<div class="layui-input-block">
						<input type="radio" name="state" value="1" title="启用" checked="">
						<input type="radio" name="state" value="2" title="停用">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="demo1"><i class="layui-icon">&#x1005;</i>添加</button>
				</div>
			</div>
		</form>
	</body>
	<script src="${BASE_PATH}/static/lib/layui/layui.js"></script>
	<script>
		layui.use(['form', 'layedit', 'laydate', 'jquery', 'table'], function() {
			var form = layui.form,
				layer = layui.layer;
			var $ = layui.jquery;
			var table = layui.table;
			var laydate = layui.laydate;

			//出生日期
			laydate.render({
				elem: '#test1'
			});

			//自定义验证规则
			form.verify({
				yhUserName: function(value) {
					if(value.length < 1) {
						return '姓名不能为空';
					}
				},
				yhUserAdds: function(value) {
					if(value.length < 1) {
						return '家庭住址不能为空';
					}
				}
			});

			//监听提交
			form.on('submit(demo1)', function(data) {
				$.ajax({
					type: 'POST',
					url: '${BASE_PATH}/admin/manage/ajax_manage_user_add',
					data: data.field,
					success: function(res) {
						if(res.success == true) {
							alert(res.msg);
							parent.location.reload();
						} else {
							alert("添加失败，请稍后再试！");
							parent.location.reload();
						}
					}
				})
				return false;
			});
			
			//身份证失焦
			$("#ddd").on("blur",function(){
				var idCard = $("#idCard").val();
				$.ajax({
					type:'POST'
					,url:'${BASE_PATH}/admin/user/ajax_user_idCard'
					,data:{yhUserIdcard:idCard}
					,success:function(res){
						if(res.success == true){
							alert(res.msg)
							parent.location.reload();
						}
					}	
				})
			})

		});
	</script>

</html>